package com.atues.thread.state;

public class TestYiled {


    public static void main(String[] args) {
        MyYield myYield = new MyYield();
        myYield.start();
        for (int i = 0; i < 10; i++) {
            if (i % 2 == 0) {
                System.out.println(Thread.currentThread().getName() + " yield");
                Thread.yield(); // 让步
            }
            System.out.println(Thread.currentThread().getName() + " " + i);
        }
    }

}

class MyYield extends Thread {
    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            if (i % 2 == 0) {
                System.out.println(getName() + " yield");
                yield(); // 让步
            }
            System.out.println(getName() + " " + i);
        }
    }
}


